#include <iostream>
#include <vector>
#include "PlayerController.h"

// 示例回调实现
class ConsoleLogger : public EventCallback {
public:
    void OnDownloadStart(const std::string &url) override
    {
        std::cout << "[Download] Start: " << url << std::endl;
    }

    void OnDownloadProgress(const std::string &url, size_t downloaded, size_t total) override
    {
        if (total > 0) {
            int percent = static_cast<int>(downloaded * 100 / total);
            std::cout << "[Download] Progress: " << url << " - " << percent << "% (" << downloaded << "/" << total
                      << ")\n";
        }
    }

    void OnDownloadComplete(const std::string &url) override
    {
        std::cout << "[Download] Complete: " << url << std::endl;
    }

    void OnDownloadError(const std::string &url, const std::string &error) override
    {
        std::cerr << "[Download] Error: " << url << " - " << error << std::endl;
    }

    void OnPlayStart(const std::string &url) override
    {
        std::cout << "[Play] Start: " << url << std::endl;
    }

    void OnPlayPause() override
    {
        std::cout << "[Play] Paused" << std::endl;
    }

    void OnPlayResume() override
    {
        std::cout << "[Play] Resumed" << std::endl;
    }

    void OnPlayStop() override
    {
        std::cout << "[Play] Stopped" << std::endl;
    }

    void OnPlayFinished(const std::string &url) override
    {
        std::cout << "[Play] Finished: " << url << std::endl;
    }

    void OnPlayError(const std::string &error) override
    {
        std::cerr << "[Play] Error: " << error << std::endl;
    }
};

int main()
{
    PlayerController controller;
    ConsoleLogger logger;
    controller.SetEventCallback(&logger);

    // 添加播放列表
    controller.AddToPlaylist("https://dds-ack.dui.ai/runtime/v1/longtext/cbb50b56bb744b008cacea5451cab6c2?productId=279630207&aispeech-da-env=hd-ack");
    controller.AddToPlaylist("http://mp3cdn.hifiok.com/14/03/"
                             "F1FFaCe7d30CeAB1Ba5b82321598ffcc.mp3?auth_key=1750892604-"
                             "c88a092ab52a44f096a9f2882e3ce735-0-822544b1fe6bc4f25e24bc93bec6d49a");
    // controller.AddToPlaylist("https://example.com/song3.mp3");

    // 启动播放
    controller.Play();

    // 用户控制界面
    std::string command;
    while (true) {
        std::cout << "\nCommand (play, pause, stop, next, prev, add, list, quit): ";
        std::getline(std::cin, command);

        if (command == "play") {
            controller.Play();
        } else if (command == "pause") {
            controller.Pause();
        } else if (command == "stop") {
            controller.Stop();
        } else if (command == "next") {
            controller.Next();
        } else if (command == "prev") {
            controller.Previous();
        } else if (command == "add") {
            std::string url;
            std::cout << "Enter URL: ";
            std::getline(std::cin, url);
            controller.AddToPlaylist(url);
        } else if (command == "list") {
            std::cout << "Current playlist:\n";
            // 实际应用中应实现获取播放列表方法
        } else if (command == "quit") {
            controller.Stop();
            break;
        }
    }

    return 0;
}